Strict

Import agfx

Global myTmpScreen:TTmpScreen

Class TAgfx_test_app Extends TFramework

	Method OnCreate:Int()
		
		Super.OnCreate()
				
		myTmpScreen = New TTmpScreen		
		myTmpScreen.Prepare()
		
		Return 0
	End
		
End


Class TTmpScreen Extends TScreen

	Field fList:TFastList<TVector2>
	Field sList:List<TVector2>
	Field aList:ArrayList<TVector2>

	Field start_time:Int
	' START when app is created
	Method Start:Void()
		Self.fList = New TFastList<TVector2>()
		Self.sList = New List<TVector2>()
		Self.aList = New ArrayList<TVector2>()
		Local v:TVector2 
		Local itm:TVector2

		Self.start_time = Millisecs()
		
		Print("Create Fast Object List")		
		For Local i:Int = 0 To 10000
			Self.fList.Add(New TVector2(i,i))
		Next
		Print("End: "+(Millisecs()-Self.start_time)+" ms")
		
		Self.start_time = Millisecs()
		Print("Create Object List")
		For Local i:Int = 0 To 10000
			Self.sList.AddLast(New TVector2(i,i))
		Next
		Print("End: "+(Millisecs()-Self.start_time)+" ms")
		
		
		Print("READ From Fast List with EachIn loop ")
		Self.start_time = Millisecs()		
		For itm = EachIn Self.fList
			v = itm
		Next
		Print("End: "+(Millisecs()-Self.start_time)+" ms")

		Print("READ From Fast List with EachIn loop with refer. out of loop")

		Self.start_time = Millisecs()		
		For  itm = EachIn Self.fList
			v = itm
		Next
		Print("End: "+(Millisecs()-Self.start_time)+" ms")
		
		Print("READ From Fast List with While loop ")
		Local itm1  := Self.fList.FirstNode()				
		Self.start_time = Millisecs()		
		While( Not( itm1 = null ) ) 				
			' little bit slow		
			' Local v:TVector2 = itm.Value()			
			' very quick
			v = itm1.elt
			itm1 = itm1.nextItem			
		Wend
		Print("End: "+(Millisecs()-Self.start_time)+" ms")
		
		Print("READ From List")
		Self.start_time = Millisecs()
		For itm = EachIn Self.sList
			v = itm
		Next
		Print("End: "+(Millisecs()-Self.start_time)+" ms")


		Print("Create ArrayList ")		
		For Local i:Int = 0 To 10000
			Self.aList.AddLast(New TVector2(i,i))
		Next
		Print("End: "+(Millisecs()-Self.start_time)+" ms")

		Print("READ From ArrayList with eachin")
		Self.start_time = Millisecs()
		For itm = EachIn Self.aList
			v = itm
		Next
		Print("End: "+(Millisecs()-Self.start_time)+" ms")


		Print("READ From ArrayList with While")
		Local oe:AbstractEnumerator<TVector2> = Self.aList.Enumerator()

		Self.start_time = Millisecs()
		While (oe.HasNext())
			v = oe.NextObject()
		End
		Print("End: "+(Millisecs()-Self.start_time)+" ms")

		
	End
	
	' main app logic loop update
	Method Update:Void()
		
	End
	
	' main app render loop
	Method Render:Void()
		
	End
End
